package com.finance.cooperate.dao.repository.secondary;

import com.finance.cooperate.dao.entity.secondary.ScrapyApp;
import com.finance.cooperate.dao.support.dto.ScrapyAppCategoriesDTO;
import com.finance.cooperate.dao.support.jpa.BaseRepository;
import com.finance.cooperate.dao.support.upk.ScrapyAppUPK;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @InterfaceName ScrapyAppRepository
 * @Description app爬虫仓库
 * @Author shen
 * @Date 2022/9/14 14:31
 * @Modify ...
 */
@Repository
public interface ScrapyAppRepository extends BaseRepository<ScrapyApp, ScrapyAppUPK> {

    /**
     * @Author shen
     * @Description 根据类目ID查询
     * @Date 15:11 2022/9/14
     * @Param [categoriesId]
     * @return java.util.List<com.finance.cooperate.dao.support.dto.ScrapyAppListCategoriesDTO>
     **/
    @Query(value = "SELECT id, categories_id, stores_id, categories_name, monetization_isFree, monetization_hasIaps, monetization_hasAds, monetization_price, downloads, rating_count, rating_stars, countries, langs, download_size, content_rating_value, inferred_gender_classification, inferred_age_percentages, inferred_female_percent FROM rc_scrapy_applist WHERE categories_id = ?1 AND project = 'mexico'", nativeQuery = true)
    List<ScrapyAppCategoriesDTO> findByCategories(String categoriesId);



    /**
     * @Author shen
     * @Description 根据类目ID查询 top N
     * @Date 15:11 2022/9/14
     * @Param [categoriesId, count]
     * @return java.util.List<com.finance.cooperate.dao.support.dto.ScrapyAppListCategoriesDTO>
     **/
    @Query(value = "SELECT id, categories_id, stores_id, categories_name, monetization_isFree, monetization_hasIaps, monetization_hasAds, monetization_price, downloads, rating_count, rating_stars, countries, langs, download_size, content_rating_value, inferred_gender_classification, inferred_age_percentages, inferred_female_percent FROM rc_scrapy_applist WHERE categories_id = ?1 AND project = 'mexico' ORDER BY downloads + 0 DESC, rating_count + 0 DESC, updated_date DESC LIMIT ?2", nativeQuery = true)
    List<ScrapyAppCategoriesDTO> findByCategories(String categoriesId, int count);


}
